package action.admin.FAQ;

import dao.FAQ;
import dao.MngClass;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "editFAQ", urlPatterns = {"/editFAQ"})
public class editFAQ extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String action = request.getParameter("action");
            if (action.equals("delete")) {
                String faq_id = request.getParameter("faq_id");
                FAQ faq = new FAQ();
                String msg = "";
                String error= "";
                if (faq.deleteFAQ(faq_id)) {
                    msg = "Delete successful !";
                } else {
                    error = "Delete error !";
                }
                request.setAttribute("msg", msg);
                request.setAttribute("error", error);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=faq");
                rd.forward(request, response);
            } else if (action.equals("update")) {
                String faq_id = request.getParameter("faq_id");
                String question = request.getParameter("question");
                String answer = request.getParameter("answer");

                request.setAttribute("faq_id", faq_id);
                request.setAttribute("question", question);
                request.setAttribute("answer", answer);

                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=update_FAQ");
                rd.forward(request, response);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
